<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="gv-forms" layout="column">
  <div class="gv-forms-header">
    <h1>{{$ctrl.createMode ? 'New' : 'Edit'}} quality rule</h1>
    <a ui-sref="management.settings.apiQuality">Back to quality rules</a>
  </div>
  <form name="$ctrl.qualityRuleForm" ng-submit="$ctrl.save()">
    <div class="gv-form">
      <h2>General</h2>
      <div class="gv-form-content" layout="column">
        <div layout="row">
          <div layout="column" flex>
            <div layout-gt-sm="row">
              <md-input-container class="md-block" flex-gt-sm>
                <label>Name</label>
                <input ng-model="$ctrl.qualityRule.name" type="text" required name="name" maxlength="64">
                <div class="hint" ng-if="$ctrl.qualityRuleForm.name.$valid || $ctrl.qualityRuleForm.name.$pristine">Quality rule name</div>
                <div ng-messages="$ctrl.qualityRuleForm.name.$error">
                  <div ng-message="required">Quality rule name is required.</div>
                  <div ng-message="md-maxlength">The name has to be less than 64 characters long.</div>
                </div>
              </md-input-container>
            </div>

            <div layout-gt-sm="row">
              <md-input-container class="md-block" flex-gt-sm>
                <label>Description</label>
                <input ng-model="$ctrl.qualityRule.description" type="text" required name="description" maxlength="256">
                <div class="hint" ng-if="$ctrl.qualityRuleForm.description.$valid || $ctrl.qualityRuleForm.description.$pristine">Quality rule description</div>
                <div ng-messages="$ctrl.qualityRuleForm.description.$error">
                  <div ng-message="required">Quality rule description is required.</div>
                  <div ng-message="md-maxlength">The description has to be less than 256 characters long.</div>
                </div>
              </md-input-container>
            </div>

            <md-input-container class="md-block" flex="50"  flex-gt-xs="100" flex-gt-sm="50">
              <label>Weight</label>
              <input type="number" min="0" max="99999" ng-model="$ctrl.qualityRule.weight">
            </md-input-container>
          </div>
        </div>
      </div>
    </div>
    <div layout="row">
      <md-button ng-disabled="$ctrl.qualityRuleForm.$invalid || $ctrl.qualityRuleForm.$pristine && !$ctrl.formChanged"
                 type="submit"
                 permission permission-only="['environment-quality_rule-c', 'environment-quality_rule-u']"
                 class="md-raised md-primary">
        Save
      </md-button>
    </div>
  </form>
</div>
